/*年轻人，只管向前看，不要管自暴自弃者的话*/

import 'dart:convert';

import 'package:get/get.dart';

import '../db/data_manager.dart';
import '../page/video_doctor/video_doctor_logic.dart';
import '../routes/router.dart';
import 'mqtt_data.dart';

///create by itz on 2023/11/16 11:45
///desc :

class MqttManager {
  /// 就诊中(医生接入)
  static const String cmdUnderTreatment = "under_treatment";

  /// 视频问诊挂断
  static const String cmdHangUp = "hang_up";

  static void receiveMsg(String data) {
    MqttData mqttData = MqttData.fromJson(json.decode(data));
    print("MqttManager receiveMsg: $mqttData");
    switch (mqttData.cmd) {
      case cmdUnderTreatment:
        dataManager.treatmentData = mqttData.data as TreatmentData;
        if (dataManager.callVideo) {
          /// 正在视频问诊页面
          final logic = Get.find<VideoDoctorLogic>();
          if (dataManager.treatmentData != null) {
            logic.treatmentData.value = dataManager.treatmentData!;
          }
          logic.index.value = 2;
        } else {
          Get.toNamed(AppRoutes.videoDoctor, arguments: {"index": 2});
        }
        break;

      case cmdHangUp:
        if (dataManager.callVideo) {
          /// 正在视频问诊页面
          final logic = Get.find<VideoDoctorLogic>();
          logic.index.value = 3;
        }
        break;

      default:
        break;
    }
  }
}
